package com.nitty.cash.loop.common

import android.content.Context
import android.view.Gravity
import android.view.WindowManager
import com.nitty.cash.loop.NittyApp
import com.nitty.cash.loop.R
import com.nitty.cash.loop.base.BaseDialog
import com.nitty.cash.loop.event.NittyEventPointHelper
import com.nitty.cash.loop.request.HttpHelper
import com.nitty.cash.loop.request.IHttpCallback
import com.nitty.cash.loop.utils.NittyDensityUtil
import org.json.JSONObject

/**
 * CommonDialog
 * @Author wwdeng
 * @CreateTime: 2024/11/28 10:32
 * @Annotation：
 */
abstract class CommonDialog(context: Context): BaseDialog(context) {

    override fun initWindow() {
        val params = window!!.attributes
        params.width = NittyApp.app.getPhoneWidth() - NittyDensityUtil.dp2px(32f)
        params.height = WindowManager.LayoutParams.WRAP_CONTENT
        window!!.attributes = params
        window!!.setWindowAnimations(R.style.dialog_scale_anim) //修改动画样式
        window!!.setGravity(Gravity.CENTER)
    }

    /**
     * post
     */
    fun doPostAction(httpUrl: String, params: JSONObject, callback: IHttpCallback){
        HttpHelper.post(httpUrl,params,callback)
    }

    /**
     * 添加埋点
     */
    fun addEventPointRequestAction(eventName: String, eventRemark: String = "") {
        NittyEventPointHelper.addEventPointRequestAction(eventName,eventRemark)
    }

    /**
     * getString
     */
    fun getString(strId: Int): String{
        return NittyApp.app.getString(strId)
    }

    override fun show() {
        super.show()
        HttpHelper.setTag(this)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.cancelTag(this)
    }
}